<%-- 
 *Workshop 
 *Class ID        : SE0691   
 *Student ID      : SE90009
 *Student Name    : Phạm Nguyễn Nhật Trung
 *Due Date        : Nov 22, 2012, 3:13:54 AM
 *I declare that this assignment is my own work
 *in accordance with FPT Policy.
--%>

<%@page import="tracker.entity.UsersEntity"%>
<%@page import="tracker.stub.UsersSessionStub"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <LINK REL=StyleSheet HREF="style/style.css" TYPE="text/css" MEDIA=screen>
        <title>Users List Page</title>
    </head>
    <body>
        <%
            Boolean isLogin = false;
            Cookie[] ck = request.getCookies();
            try { //Check isLogin
                if (ck != null) {
                    for (int i = 0; i < ck.length; i++) {
                        if ("userId".equals(ck[i].getName())) { //Finding Username Cookie                
                            i = ck.length;
                            isLogin = true;
                        }
                    }

                }
            } catch (Exception e) {
            }
            if (isLogin == false) {
                response.sendRedirect("login.jsp");
                return;
            }
        %>
        <jsp:include page="navigation.jsp" />
        <div class="contents">
            <div id="torrent-list-form" style="margin-top: 10px">
                <div style="padding-left: 10px;"><h2>Torrent List</h2></div>

                <ul id="holder">
                    <%
                        try {
                            UsersSessionStub stub = new UsersSessionStub();
                            List<UsersEntity> list = stub.findAll();
                            if (!list.isEmpty()) { //Get All Users
                                Iterator<UsersEntity> it = list.iterator();

                                while (it.hasNext()) { //Prints
                                    out.println("<li>");
                                    UsersEntity entity = it.next();
                                    out.println("<a href=\"singleUser.jsp?userId=" + entity.getUserId() + "\">");
                                    out.println("<h3>" + entity.getUserName() + "</h3></a>" + "<div id=\"torrentDate\"><a> User Level: " + entity.getUserLevel() + "</a></div>");
                                    out.println("<h4 style=\"color:green;\">Leech Amount: " + entity.getLeechAmount() + " GB</h4>");
                                    out.println("<h4 style=\"color:purple;\">Seed Amount: " + entity.getSeedAmount() + " GB</h4>");
                                    out.println("</li>");
                                }
                            }
                        } catch (Exception e) {
                        }
                    %>
                </ul> 
            </div>
            <script type="text/javascript" src="scripts/jquery.js"></script>
            <script type="text/javascript" src="scripts/pagination.js"></script>
        </div>
        <script src="scripts/meny.min.js"></script>
        <script>
            // Create an instance of Meny
            var meny = Meny.create({
                // The element that will be animated in from off screen
                menuElement: document.querySelector( '.meny' ),

                // The contents that gets pushed aside while Meny is active
                contentsElement: document.querySelector( '.contents' ),

                // [optional] The alignment of the menu (top/right/bottom/left)
                position: Meny.getQuery().p || 'left',

                // [optional] The height of the menu (when using top/bottom position)
                height: 200,

                // [optional] The width of the menu (when using left/right position)
                width: 260,

                // [optional] Distance from mouse (in pixels) when menu should open
                threshold: 40
            });

            // Embed an iframe if a URL is passed in
            if( Meny.getQuery().u && Meny.getQuery().u.match( /^http/gi ) ) {
                var contents = document.querySelector( '.contents' );
                contents.style.padding = '0px';
                contents.innerHTML = '<div class="cover"></div><iframe src="'+ Meny.getQuery().u +'" style="width: 100%; height: 100%; border: 0; position: absolute;"></iframe>';
            }
        </script> 
    </body>
</html>
